package cn.miju.admin.system.controller;

import cn.miju.admin.framework.annotation.NoToken;
import cn.miju.admin.system.service.UserService;
import cn.miju.admin.system.vo.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <pre>
 * 用户
 * </pre>
 *
 * @author zhuming
 * @version 1.0.0
 * @since 2023-03-31 10:02
 */
@RestController
@Api(tags = "系统-用户管理")
@ApiSort(3)
@RequestMapping("/system/user")
public class UserController {
    private final UserService service;

    public UserController(UserService service) {
        this.service = service;
    }

    /**
     * 用户分页查询
     * @param inVO {@link UserPageInVO}
     * @return {@link Page<UserPageOutVO>}
     */
    @ApiOperation("用户分页查询")
    @ApiOperationSupport(order = 1, author = "zhuming")
    @GetMapping("/page")
    public Page<UserPageOutVO> getPage(@ModelAttribute @Validated UserPageInVO inVO) {
        return service.getPage(inVO);
    }

    /**
     * 保存用户
     * @param inVO {@link UserSaveInVO}
     */
    @ApiOperation("保存用户")
    @ApiOperationSupport(order = 2, author = "zhuming")
    @PostMapping("/save")
    public void save(@RequestBody @Validated UserSaveInVO inVO) {
        service.save(inVO);
    }
    /**
     * 批量删除用户
     * @param inVO {@link UserDeleteInVO}
     */
    @ApiOperation("批量删除用户")
    @ApiOperationSupport(order = 3, author = "zhuming")
    @PostMapping("/deletes")
    public void deletes(@RequestBody @Validated UserDeleteInVO inVO) {
        service.deletes(inVO);
    }
    /**
     * 修改账户密码
     * @param inVO {@link UpdatePasswordInVO}
     */
    @ApiOperation("修改账户密码")
    @ApiOperationSupport(order = 10, author = "zhuming")
    @PostMapping("/updatePassword")
    public void updatePassword(@RequestBody @Validated UpdatePasswordInVO inVO) {
        service.updatePassword(inVO);
    }

    /**
     * 修改账户信息
     * @param inVO {@link UpdateAccountInfoInVO}
     */
    @ApiOperation("修改账户信息")
    @ApiOperationSupport(order = 11, author = "zhuming")
    @PostMapping("/updateAccountInfo")
    public void updateAccountInfo(@RequestBody @Validated UpdateAccountInfoInVO inVO) {
        service.updateAccountInfo(inVO);
    }

    /**
     * 重置密码
     * @param inVO {@link ResetPasswordInVO}
     */
    @NoToken
    @ApiOperation("重置密码")
    @ApiOperationSupport(order = 12, author = "zhuming")
    @PostMapping("/resetPassword")
    public void resetPassword(@RequestBody @Validated ResetPasswordInVO inVO) {
        service.resetPassword(inVO);
    }
}
